<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<div class="page_right">
    <p class="settings_createCode_p">
        <span style="font-size:18px;color:#333;margin-right:20px;">生成二维码</span>
        <span>工厂简码：</span>
        <span class="settings_factoryCodeText">${!empty shortCode?shortCode:'未设置'}</span>
        <a class="settings_factoryCodeUrl" href="${basePath}v2/factory/manage/showShortCodeView" style="${!empty shortCode?'display:block':'display:none'}">去设置>></a>
    </p>
    <div class="settings_createCode_dv" style="${!empty shortCode?'display:block':'display:none'}">
        <span>数量：</span>
        <input class="settings_createCode_number" type="text" placeholder="请输入二维码生成数量">
        <input class="settings_createCode_btn" type="button" disabled="disabled" value="生成二维码">
    </div>

    <div style="text-align:center;"><a style="display:none;" class="settings_createCode_download" href="javascript:;">下载</a></div>
</div>
<!-- 二维码正在生成中提示 -->
<div class="pointpage_dv6" style="display:none;">
    <div class="settings_createCode_pointpage">
        <p class="settings_createCode_p2">二维码正在生成中，请等候...</p>
    </div>
</div>
<!-- 二维码正在生成中提示 end -->


<script type="text/javascript">
    //生成二维码按钮解禁
    $(".settings_createCode_number").on("keyup focus", function(){
        var settings_createCode_number=parseInt($(this).val());
        if(settings_createCode_number>0){
            $(this).val(settings_createCode_number);
            $(".settings_createCode_btn").removeAttr("disabled", "disabled");
        }else{
            $(this).val("");
            $(".settings_createCode_btn").attr("disabled", "disabled");
        }
    });

    if($(".settings_factoryCodeText").text()=="未设置"){
        $(".settings_factoryCodeUrl").stop().show();
        //设置生成二维码提示
        $(".settings_createCode_btn").on("click", function(){
            alert("未设置工厂简码，不能生成二维码");
        })
    }else{
        $(".settings_factoryCodeUrl").stop().hide();
        //设置生成二维码
        $(".settings_createCode_btn").on("click", function(){
            $(".pointpage_dv6").stop().show();
            var codeNum=$(".settings_createCode_number").val();
            $.ajax({
                url:'${basePath}v2/factory/qrcode/makeQRCode',
                type : 'POST',
                data : {"codeNum":codeNum},
                async : false,
                traditional:true,
                error: function (response) {
                    ViewHelper.func.ajaxErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        $(".pointpage_dv6").stop().hide();
                        $(".settings_createCode_download").stop().show();
                    }else{
                        $(".pointpage_dv6").stop().hide();
                        alert("生成失败!");
                    }
                }
            });
        });
    }

    $(".settings_createCode_download").on("click", function(){
        $.ajax({
            url:'${basePath}v2/factory/qrcode/checkFile',
            type : 'GET',
            async : false,
            traditional:true,
            error: function (response) {
                ViewHelper.func.ajaxErrorMessage(response);
            },
            success: function (ret) {
                if(ret.result) {
                    window.location.href = '${basePath}v2/factory/qrcode/downloadZip';
                }else{
                    alert("下载失败!");
                }
            }
        });
    });
</script>